import axios from 'axios'
import { getlocalStorage } from './localStorage'

//**做了，统一的地址地址配置
// **请求拦截器--统一处理的token--设置了请求头的token

let http = axios.create({
  // baseURL: 'http://localhost:3001',
  baseURL: import.meta.env.VITE_API_BASE_URL,
  timeout: 60000,
})

// 添加请求拦截器
http.interceptors.request.use(
  function (config) {
    let token = getlocalStorage.token
    if (token) {
      config['headers']['token'] = token
    }
    return config
  },
  function (error) {
    return Promise.reject(error)
  },
)

// let http = axios.create({
//   baseURL: 'http://localhost:3001',
//   timeout: 60000,
// })
export default http
